namespace Bowlus.FrontEnd.RequestRouting.ApplicationDeployment
{

    using Bowlus.Common;
    using Bowlus.Common.DeploymentActions;

    public class MoveApplicationRequest : ApplicationDeploymentRequest
    {
        public MoveApplicationRequest(TenantDeployment tenantDeployment, ApplicationHost fromApplicationHost, ApplicationHost toApplicationHost)
            : base(tenantDeployment)
        {
            this.FromHost = fromApplicationHost;
            this.ToHost = toApplicationHost;
        }

        public ApplicationHost FromHost { get; private set; }

        public ApplicationHost ToHost { get; private set; }

        protected override string RequestType
        {
            get
            {
                return string.Empty;
            }
        }

        public override void MakeDeploymentRequest()
        {
			//var newTenantDeployment = new TenantDeployment(this.TenantDeployment.Serialize())
			//    {
			//        Status = TenantDeploymentStatus.DeployRequestSubmitted,
			//        DeploymentAction = DeploymentActionType.DeployToAppHost,
			//        AppHostInstanceId = this.ToHost.InstanceId,
			//        AppHostInstanceIp = this.ToHost.ApphostHttpEndpoint.Address.ToString()
			//    };

			//TenantDeploymentsStore.UpdateDeploymentStore(newTenantDeployment);

            this.TenantDeployment.Status = TenantDeploymentStatus.DeployRequestSubmitted;
            this.TenantDeployment.DeploymentAction = DeploymentActionType.MoveFromAppHost;
            this.TenantDeployment.AppHostInstanceId = this.FromHost.InstanceId;
            this.TenantDeployment.AppHostInstanceIp = this.FromHost.ApphostHttpEndpoint.Address.ToString();

            TenantDeploymentsStore.UpdateDeploymentStore(this.TenantDeployment);
        }
    }
}